/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package week0402;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Scanner;

public class Main2 {

    private static Scanner in;

    public static void main(String[] args) {
        in = new Scanner(System.in);
        int n;

        while (true) {
            n = in.nextInt();
            List<PersonSortable> personSortables = new ArrayList<PersonSortable>();
            for (int i = 0; i < n; i++) {
                personSortables.add(new PersonSortable(in.next(), in.nextInt()));
            }

            NameComparator.sort(personSortables);
            System.out.println("NameComparator:sort");
            for (PersonSortable personSortable : personSortables) {
                System.out.println(personSortable.toString());
            }

            AgeComparator.sort(personSortables);
            System.out.println("AgeComparator:sort");
            for (PersonSortable personSortable : personSortables) {
                System.out.println(personSortable.toString());
            }

            System.out.println(Arrays.toString(NameComparator.class.getInterfaces()));
            System.out.println(Arrays.toString(AgeComparator.class.getInterfaces()));

        }

    }

}

class NameComparator implements Comparator<PersonSortable> {

    public int compare(PersonSortable o1, PersonSortable o2) {
        return o1.getName().compareTo(o2.getName());
    }

    public static void sort(List<PersonSortable> personSortables) {
        Collections.sort(personSortables, new NameComparator());
    }

}

class AgeComparator implements Comparator<PersonSortable> {

    public int compare(PersonSortable o1, PersonSortable o2) {
        if (o1.getAge() >= o2.getAge()) {
            return 1;
        }
        else {
            return -1;
        }
    }

    public static void sort(List<PersonSortable> personSortables) {
        Collections.sort(personSortables, new AgeComparator());
    }

}

class PersonSortable {

    private String name;
    private int age;

    public PersonSortable(String name, int age) {
        this.name = name;
        this.age = age;
    }

    @Override
    public String toString() {
        return name + "-" + age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

}